<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>选择加入公司</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <link href="<%=basepath%>css/jquery-ui.min.css" rel="stylesheet" type="text/css">
    <link href="<%=basepath%>css/index.css" rel="stylesheet" type="text/css">
    <link href="<%=basepath%>css/company.css" rel="stylesheet" type="text/css">
    <script src="<%=basepath%>js/jquery-1.8.3.min.js"></script>
    <script src="<%=basepath%>js/jquery-ui.min.js"></script>
    <script src="<%=basepath%>js/layer/layer.js"></script>
</head>
<body>
<div class="viewport">
    <div class="header">
       <div class="header-1">
           <a href="javascrpt:void(0)" id="join" class="header-2">
              <span id="account" class="account">${empty user.realName ? '' : user.realName}</span>&nbsp;&nbsp;<span id="deptName" class="deptName">${user.departmentName}</span>
           </a>
           <a href="/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=company&prefix=3g_company&entrance=yes" class="back" id="back">返回</a>
           <span class="span-num">WWP12500</span>
       </div>
    </div>
    <div class="content">
        <div class="blank-2"></div>
        <div class="content2-1 m-top">
            <div class="content2-1-1">
                <form method="post" id="myForm" action="/wape-web/api/core/centerService">
                    <input type="text" name="companyName" placeholder="输入公司名称" autocomplete="off" id="autocomplete" class="input-2">
                    <input type="hidden" name="companyId" id="companyId" />
                    <input type="hidden" name="serviceCode" value="MMZS131" />
                </form>
                <form method="post" id="myform" action="/wape-web/api/core/centerService">
                    <span class="span2-2"><input type="submit" value="查询公司" class="input-1"></span>
                    <input type="hidden" name="companyName" id="companyName-2"/>
                    <input type="hidden" name="serviceCode" value="5006U05" />
                </form>
            </div>
            <div class="blank"></div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    /*错误提示*/
    $(function(){
        var error = "${requestScope.returnMsg}";
        if(error != "" && error != "成功!"){
            layer.msg(error,{shadeClose:true,shade:0.1,time:2000});
        }
    });
    /*模糊查询*/
    $(function(){
        /*查询*/
        $("#autocomplete").keyup(function(event){
            var companyName = $("#autocomplete").val();
            if(companyName.length>=1){
                $.ajax({
                    type:"post",
                    url:"/wape-web/api/core/centerService",
                    data:{
                        serviceCode:"5006U04",
                        companyName:companyName
                    },
                    success:function(data){
                        var availableTags = eval(data);
                        $( "#autocomplete" ).autocomplete({
                            delay: 500,
                            minChars: 1,
                            source: availableTags,
                            select: function(event, ui){
                                $(this).value = ui.item.value;
                                $("#companyId").val( ui.item.value );
                                $("#autocomplete").val( ui.item.label );
                                var companyId = $("#companyId").val();
                                if(companyId != ""){
                                    $("#myForm").submit();
                                }

                                event.preventDefault();
                            }
                        });
                    }
                });
            }
        });

    });
    /*提交表单*/
    $(function(){
        /*表单*/
        $("#myForm").submit(function(){
            var input = $("#autocomplete").val();
            var join = "${user.companyName}";
            var company = $("#companyId").val();
            if(input == ""){
                layer.msg("请输入公司名",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(join != ""){
                layer.msg("您已加入公司！",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else{
                layer.load();
                setTimeout(function(){
                    layer.closeAll();
                    layer.msg("网络异常，请重新尝试！",{shadeClose:true,shade:0.1,time:2000});
                }, 30000);
            }
        });
    });
    /*查询公司*/
    $(function(){
    	$("#myform").submit(function(){
    		var companyName2 = $("#autocomplete").val();
    		if(companyName2 == ""){
    			layer.msg("请输入公司名",{shadeClose:true,shade:0.1,time:2000});
                return false;
    		}
    		else{
    			var companyName = $("#autocomplete").val();
    	    	//alert(companyName)
    	    	$("#companyName-2").val(companyName);
    			layer.load();
                setTimeout(function(){
                    layer.closeAll();
                    layer.msg("网络异常，请重新尝试！",{shadeClose:true,shade:0.1,time:2000});
                }, 30000);
    		}
    	});
    });
</script>
</html>

